package com.wc.acwing.模拟.炮弹;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/3/4 23:06
 * @description
 * https://www.acwing.com/problem/content/5528/
 */
public class Main {
    /**
     * 题意：
     * 跳跳板, 跳到击破位置, 看能量是否 >= 就击破
     * 跳到木板, 取反, 加权值
     * 思路： 模拟
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    static int[] q = new int[N], w = new int[N];
    static boolean[] st = new boolean[N];
    static int n, x;

    public static void main(String[] args) {
        n = sc.nextInt();
        x = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            q[i] = sc.nextInt();
            w[i] = sc.nextInt();
        }
        int res = 0, cnt = 0, e = 1, op = 1;
        while (cnt < 26 * n) {
            cnt++;
            if (q[x] > 0) {
                if (e >= w[x] && !st[x]) {
                    st[x] = true;
                    res++;
                }
            } else {
                e += w[x];
                op = -op;
            }
            x += e * op;
            if (x < 1 || x > n) break;
        }
        out.println(res);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

